package com.vict;

import com.vict.gui.*;
import com.vict.util.TimeUtil;

import javax.swing.*;
import java.util.Optional;

public class GuiApplication {

    public static GuiApplication guiApplication;

    private MainWIndowGui manWindow;
    private LogGui logGui;
    private DbEditGui dbEditGui;
    private AddDbConfigGui addDbConfigGui;
    private EditDbConfigGui editDbConfigGui;

    public void init(){
        manWindow = new MainWIndowGui();
        manWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        manWindow.setVisible(true);

        logGui = new LogGui();
        logGui.getLogText().setText("");

        dbEditGui = new DbEditGui();
        addDbConfigGui = new AddDbConfigGui();
        editDbConfigGui = new EditDbConfigGui();
    }

    public MainWIndowGui getMainWindow() {
        return manWindow;
    }
    public LogGui getLogGui() {
        return logGui;
    }
    public DbEditGui getDbEditGui(){
        return dbEditGui;
    }
    public AddDbConfigGui getAddDbConfigGui(){
        return addDbConfigGui;
    }
    public EditDbConfigGui getEditDbConfigGui(){
        return this.editDbConfigGui;
    }

    public static void message(String message){
        Optional.ofNullable(GuiApplication.guiApplication).map(o-> o.manWindow)
                .map(o-> o.getMessage())
                .ifPresent(o-> o.setText(TimeUtil.getTimeStr(System.currentTimeMillis()) + ", " + message));
    }
}
